package logic

import (
	"context"
	"furni-max/models/mysql"

	"furni-max/funcirpc/funcirpc"
	"furni-max/funcirpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type FuncShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFuncShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FuncShowLogic {
	return &FuncShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *FuncShowLogic) FuncShow(in *funcirpc.FuncShowRequest) (*funcirpc.FuncShowResponse, error) {
	// todo: add your logic here and delete this line

	var toolData mysql.ToolData
	mysql.DB.Debug().Model(&mysql.Tool{}).
		Select("tools.*,classes.name as classes.name as class_name,brands.name as brand_name").
		Joins("LEFT JOIN classes ON tools.class_id = classes.id").
		Where("tool.id = ?", in.ToolId).
		Joins("LEFT JOIN brands on tools.brand_id = brands.id").
		Find(&toolData)

	return &funcirpc.FuncShowResponse{
		Name:      toolData.Name,
		Price:     float32(toolData.Price),
		Stock:     toolData.Stock,
		Image:     toolData.Image,
		Info:      toolData.Info,
		ClassName: toolData.ClassName,
		BrandName: toolData.BrandName,
		ToolId:    int64(toolData.ID),
	}, nil

}
